home *** CD-ROM | disk | FTP | other *** search
- ' LMENU.SUB -- MSDOS QuickBASIC line menu subroutines 15 June 86
- ' by David L. Poskie (608) 274-9560
- ' 7118 Raymond Rd. Madison, WI 53719
- ' Please run any suggestions, corrections, additions, or changes by me.
- ' I can be messaged on all the major Madison, WI RBBS's.
-
- '| These subroutines require the main program to $Include: 'OMNI.SUB'.
- '| Subroutines:
- '| LoadLMenu -- Load the line menu array
- '| LMenu -- Set a line menu and get response
- '| Line Menu Procedures:
- '| Read up to 11 one-line menus, up to 9 selections per menu from DATA lines
- '| located in the calling program.
- '| Load menus in Menu$(n,n) by GOSUB LoadLMenu , returns LMenuMax = # of menus.
- '| LOCATE cursor before calling menu, then call a menu by:
- '| setting Num = (0 to 10) : GOSUB LMenu -- evaluate KeyCode on RETURN.
- '| Quit will always return KeyCode = -21. I use this number because <ESC> also
- '| returns -21. Thus, you can bail out of a menu with <ESC>. No other
- '| evaluation is made -- you will get any out of bounds numbers and must
- '| check for these in the main program.
- '|
- '| Saves foreground & background colors, restoring them after input.
- '|
- '| Input: KeyCode = ASCII Inkey$ code input by user
-
- '| Output: LMenuMax = Total number of line menus loaded from LMenu DATA
- '| KeyCode -- adjusted to track with selection number
- '| NumSelects() = number of selections in a given line menu
- '| Other Vars: Blank -- does internal spacing for LMenu layout
- '| LMenuNum = specific line menu
- '| Menu$() = array of line menus
- '| Num -- count of line menus in Menu$()
- '| Selection = individual selection in Menu$()
- '| Temp -- temporary count
- '| TestFG = foreground color to be restored
- '| TestBG = background color to be restored
-
- ' Subroutine to read DATA into Menu$(Num , Selection),
- ' loading all the menus and prompts.
- LoadLMenu:
- RESTORE LMenuData ' In case the pointer is
- FOR Num = 0 TO 10 ' somewhere else
- FOR Selection = 0 TO 10
- READ Menu$(Num , Selection)
- ' Look for end of ONE menu symbol
- IF Menu$(Num , Selection) = "*" _
- THEN NumSelects(Num) = Selection - 1 : _
- GOTO LoadLMenuLoop
- ' NumSelects(Num) holds number of selections
- ' Look for end of ALL menus symbol
- IF Menu$(Num , Selection) = "$" _
- THEN LMenuNum = Num - 1 : _
- GO TO LoadLMenuExit
- NEXT Selection
- ' One Menu is read
- LoadLMenuLoop:
- NEXT Num
- ' All Menus are read
- LoadLMenuExit:
- LMenuMax = Num - 1 ' Maximum number of menus
- RETURN
- '_____________________________________________________________________
-
- 'Subroutine to print the menu line and get a response
- LMenu:
- ' Read foreground color
- TestFG = ((SCREEN (1 , 1 , 1)) MOD 16)
- ' Read background color
- TestBG = (((SCREEN (1 , 1 , 1)) - TestFG) / 16) MOD 128
- ' Set blank space between selections
- Blank = 0
- FOR Temp = 0 TO NumSelects(Num)
- Blank = Blank + LEN(STR$(Temp)) + LEN(Menu$(Num , Temp)) + 2
- NEXT Temp
- Blank = INT((80 - Blank) / NumSelects(Num) - 1)
- ' Case of a negative number
- IF Blank < 0 _
- THEN Blank = 0
- ' Case of protecting Blank = 1
- IF Blank > 1 _
- THEN Blank = INT(Blank / 2)
- ' Print menu line
- COLOR 0 , 7
- FOR Temp = 1 TO NumSelects(Num)
- PRINT SPC(Blank); STR$(Temp); SPC(Blank); Menu$(Num , Temp); " █";
- NEXT Temp
- ' Print prompt and get menu selection
- COLOR 31 , 0
- PRINT " « ";
- COLOR 15
- PRINT Menu$(Num , 0);
- GOSUB GetKeyClear
- KeyCode = KeyCode - 48 ' Adjust to track with number
- ' Make any Quit Command = -21
- IF KeyCode = NumSelects(Num) _
- THEN KeyCode = -21 ' Allows bailout on <ESC>
- ' Restore colors & go
- COLOR TestFG , TestBG
- RETURN
- ' >>>>> Physical EOF LMENU.SUB 18 June 86